package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.ApprovalFileDao;
import cn.topevery.garden.entity.po.ApprovalFile;
import cn.topevery.garden.entity.query.ApprovalFileQuery;
import cn.topevery.garden.entity.vo.ApprovalFileVO;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.framework.db.base.BaseEntityDao;
import hw.topevery.framework.db.entity.DataPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 批后数据 附件表
 *
 * @author code-generate
 * @date 2022-02-16
 */
@Service
public class ApprovalFileLogic extends BaseLogic<ApprovalFile> {
    @Autowired
    ApprovalFileDao approvalFileDao;

    @Override
    public BaseEntityDao<ApprovalFile, Integer> getDao() {
        return approvalFileDao;
    }

    

    /**
     * 获取列表
     *
     * @param query
     */
    public DataPager<ApprovalFileVO> listPage(ApprovalFileQuery query) {
        return approvalFileDao.listPage(query);
    }

    /**
     * 根据自增id批量删除
     *
     * @param ids
     */
    public void deleteBatchById(String userId,Integer[] ids) {
        approvalFileDao.delete(userId, ids);
    }

    /**
     * 根据自增id保存或者更新
     *
     * @param approvalFile 实体
     */
    public void saveOrUpdate(String userId, ApprovalFile approvalFile){
        approvalFileDao.saveOrUpdate(userId,approvalFile);
    }

    /**
         * 根据自定义列值来获取对象
         */
    public ApprovalFile getEntityByColumn(String key, String value) {
        return approvalFileDao.getEntityByColumn(key, value);
    }

    public List<ApprovalFile> getListByPid(Integer pid) {
        return approvalFileDao.getListByPid(pid);
    }

    public void saveOrUpdate(String userId, Integer pId, List<ApprovalFile> fileList) {
        approvalFileDao.deleteById(pId);
        for (ApprovalFile approvalFile : fileList) {
            approvalFile.setMainId(pId);
            approvalFileDao.saveOrUpdate(userId, approvalFile);
        }
    }
}
